package com.lvcoding.common;

import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter;

/**
 * @author wuyanshen
 * @discription jwt令牌注入userDetailsService，这样通过SecurityContextHolder.getContext().getAuthentication().getPrincipal()获得的就不只是名字了
 * @date 2021-02-25 下午12:53
 */
public class OauthAccessTokenConverter extends DefaultAccessTokenConverter {

    public OauthAccessTokenConverter(UserDetailsService userDetailsService) {
        DefaultUserAuthenticationConverter converter = new DefaultUserAuthenticationConverter();
        converter.setUserDetailsService(userDetailsService);
        super.setUserTokenConverter(converter);
    }
}
